<?php

/**
 * This is the model class for table "employee".
 *
 * The followings are the available columns in table 'employee':
 * @property integer $id
 * @property string $fname
 * @property string $lname
 * @property string $mi
 * @property integer $address_no
 * @property string $address_street
 * @property string $address_city
 * @property integer $address_zip
 * @property integer $work_phone
 * @property integer $home_phone
 * @property integer $user_id
 * @property integer $personal_information_id
 *
 * The followings are the available model relations:
 * @property PersonalInformation $personalInformation
 * @property Rx[] $rxes
 */
class Employee extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Employee the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'employee';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('fname, lname, mi, address_no, address_street, address_city, user_id', 'required'),
			array('address_no, address_zip, work_phone, home_phone, user_id, personal_information_id', 'numerical', 'integerOnly'=>true),
			array('fname, lname, address_city', 'length', 'max'=>45),
			array('mi', 'length', 'max'=>4),
			array('address_street', 'length', 'max'=>80),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, fname, lname, mi, address_no, address_street, address_city, address_zip, work_phone, home_phone, user_id, personal_information_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'personalInformation' => array(self::BELONGS_TO, 'PersonalInformation', 'personal_information_id'),
			'rxes' => array(self::HAS_MANY, 'Rx', 'employee_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'fname' => 'First name',
			'lname' => 'Last name',
			'mi' => 'Mi',
			'address_no' => 'Address No',
			'address_street' => 'Street',
			'address_city' => 'City',
			'address_zip' => 'Zip',
			'work_phone' => 'Work Phone',
			'home_phone' => 'Home Phone',
			'user_id' => 'User ID',
			'personal_information_id' => 'Personal Information',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('fname',$this->fname,true);
		$criteria->compare('lname',$this->lname,true);
		$criteria->compare('mi',$this->mi,true);
		$criteria->compare('address_no',$this->address_no);
		$criteria->compare('address_street',$this->address_street,true);
		$criteria->compare('address_city',$this->address_city,true);
		$criteria->compare('address_zip',$this->address_zip);
		$criteria->compare('work_phone',$this->work_phone);
		$criteria->compare('home_phone',$this->home_phone);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('personal_information_id',$this->personal_information_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
			public function getEFullName(){
                return $this->fname.' '.$this->mi.'. '.$this->lname;
				}
}